from django.shortcuts import render

# Create your views here.
# coding=utf-8
from django.http import HttpResponse
import hashlib

def wechat(request):
        token = "lichun19960112"

        signature = request.GET['signature']
        timestamp = request.GET['timestamp']
        nonce = request.GET['nonce']

        args = [token, timestamp, nonce]
        args.sort()

        if hashlib.sha1("".join(args)).hexdigest() == signature:
            if request.GET['echostr']:
                return HttpResponse(request.GET['echostr'])
        else:
            return HttpResponse("Invalid Request")